package todo_api

import (
	"fmt"

	"github.com/daqing/airway/app/models"
	"github.com/daqing/airway/lib/db"
	"github.com/daqing/airway/lib/resp"
	"github.com/daqing/airway/lib/sql"
	"github.com/gin-gonic/gin"
)

type TodoItem struct {
	Id    int    `json:"id"`
	Title string `json:"title"`
}

func IndexAction(c *gin.Context) {
	list, err := db.Find[models.TodoItem](sql.H{})
	if err != nil {
		fmt.Println(err)
		resp.Error(c, err)
		return
	}

	fmt.Printf("list is %d, %v\n", len(list), list)

	resp.OK(c, gin.H{"list": list})
}
